<?php echo $header;echo $sidebar ?>


		<div class="span10 content">	
			<?php echo $hugemenu ?> 
                    
                        <!--div class="btn-toolbar">                
                            <a class="btn" href="<?php echo site_url();?>timesheets/add">
                            <i class="icon-plus"></i> <?php echo lang('hrm_sidemenu_timesheet_new')?>
                            </a>            
                        </div-->
<script>


function changeToSubmittedBooking(theCssId) {

	window.location.href = 'http://online-marriage-counseling.net/index.php/booking/bookingavailability/'+theCssId;
		
}

$(document).ready(function(){

$('#customer_id').change(function(){

		var val = $(this).val();
		window.location.href = 'http://online-marriage-counseling.net/index.php/booking/bookingavailability/'+val;
		});
	
});
</script>                        
			<h1><?php echo "Bookings"; ?></h1> 
                        
                        <?php //echo form_open_multipart(current_url(), array('class' => 'form-horizontal')); ?>
                                <?php   
                                        $options = array();
                                        foreach ($userlist as $user): 
                                            $options[$user->id] = $user->name;
                                        endforeach;

                                        $value = ($filter_user? $filter_user : '');

                                        echo form_dropdown('user_id', $options, $value,'id="customer_id"','onChange="changeToSubmittedBooking(this.val)"');
                                ?>
                                <!--a class="btn" href="<?php //echo site_url();?>timesheets/all">Table View</a-->
                        <?php //echo form_close(); ?>
                        <br/>
			<?php if ($this->session->flashdata('message')) { ?>
					<div class="alert alert-success">
						<?php echo $this->session->flashdata('message') ?> 
					</div>   
			<?php } ?> 
                        <div>   
			<script type="text/javascript">
			plgFcRoot = '<?php echo site_url(); ?>';
			//FcUser = '<?php //echo $user_id; ?>';
			FcEvents = <?php echo json_encode($calendarTimesheets); ?>;
			</script>

			<link rel='stylesheet' href='<?php echo base_url(); ?>assets/admin/fullcalendar/cupertino/jquery-ui.min.css' />
			<link href='<?php echo base_url(); ?>assets/admin/fullcalendar/fullcalendar/fullcalendar.css' rel='stylesheet' />
			<link href='<?php echo base_url(); ?>assets/admin/fullcalendar/fullcalendar/fullcalendar.print.css' rel='stylesheet' media='print' />
			<script src='<?php echo base_url(); ?>assets/admin/fullcalendar/lib/jquery-ui.custom.min.js'></script>
                        <script src='<?php echo base_url(); ?>assets/admin/fullcalendar/lib/jquery.qtip-1.0.0-rc3.min.js'></script>
			<script src='<?php echo base_url(); ?>assets/admin/fullcalendar/fullcalendar/fullcalendar.min.js'></script> 
                        <script src='<?php echo base_url(); ?>assets/admin/fullcalendar/lib/ready.js'></script> 
                        <script src='<?php echo base_url(); ?>assets/admin/js/hrm_calender.js'></script> 
                        


                        <div id='hrm_calendar'></div>
			<div class="calendar-box" >
                                <?php /* ?>
				<div>
					<h3><?php echo __('Timesheet Calendar'); ?>
					<?php echo $this->Form->create('Timesheet', array('url' => array_merge(array('action' => 'all'), $this->params['pass']),'class'=>'form-inline')); ?>
					<?php echo $this->Form->input('search_user_id',array('options'=>$userList,'div'=>false,'label'=>false,'empty'=>'(Select Employee)','id'=>'user-filter')); ?>
					<?php echo $this->Form->input('view',array('type'=>'hidden','value'=>'table')); ?>
					<!-- <a href="<?php //echo $this->Html->url(array('controller'=>'timesheets','action'=>'all')); ?>" class="btn btn-success"><?php echo __('Table View'); ?></a> -->
					<?php echo $this->Form->submit('Table View',array('div'=>false,'class'=>'btn btn-success')); ?>
					<?php echo $this->Form->end(); ?>
					</h3>
				</div>
                                <?php */ ?>
				<!--div id="calendar"></div-->
			</div>
			<div id="dialog-form-add"></div>
			
                         
			
			
<script>




jQuery(function($) {
	$('#customer_id').change(function(){
		var val = $(this).val();
		window.location.href = 'http://online-marriage-counseling.net/index.php/booking/bookingavailability/'+val;
		});
	
	
	
	
	$('.change-status').click(function(){
		var tid = $(this).attr('timesheetid');
		var sid = $(this).attr('statusid');
		var thisIcon = $(this);

		$.post('http://localhost/hr/timesheets/changeStatus/'+tid,{statusid:sid},function(data){
				if (data == 'Ok') {
					$('.row-'+tid).removeClass('status-active');
					thisIcon.addClass("status-active");		
				}
				else {
					
				}
			});
	});

	$("#note").keypress(function(e){
		if(e.which == 13){
			var usr = $('#user-filter').val();
			addTimesheet(usr);
			//alert('hola');
		}
		});
});




function showAddForm(startTime, endTime, usr){

	$("#start_time").val(startTime);
	$("#end_time").val(endTime);
	$("#user_id").val(usr);
	
	var title = $('#note').val();
	alert(startTime);
	alert(endTime);
	alert(usr);
	alert(title);
	
	$( "#dialog-form-add" ).dialog({
		autoOpen: true,
		height: 300,
		width: 450,
		modal: true,
		buttons: {
			
			"Add": function(){
				addTimesheet(usr);
				}
		}
	});
}

function addTimesheet(usr){
	$.ajax({
        type: "post",
        url: 'http://localhost/hr/timesheets/add',
        data: $("#add-form").serialize(), // serializes the form's elements.
        beforeSend: function(){
				$('#progress').show();
            },
        success: function(data)
        {
	           if(data=='Ok'){
	        	   	//alert(data); // show response from the php script.
	        	   	//now update calendar
	        	   	/*
	        	   	calendar.fullCalendar('renderEvent',
						{
							title: title,
							start: startTime,
							end: endTime,
						},/'+usr;
						true // make the event "stick"
					);
					*/
	        	   	window.location.href = 'http://localhost/hr/timesheets/calendar/'+usr;
	           } else {
					alert(data);
					$( "#dialog-form-add").dialog( "close" );
		       }
        }
      });
	
}


$(document).ready(function(){
				$.ajax({
					url: "<?php echo $this->Html->url(array('controller'=>'timesheets','action'=>'add'),true); ?>",
					success: function(data){
						$("#dialog-form-add").html(data);
					}   
				});

				$( "#dialog-form-add" ).dialog({
					autoOpen: false,
					height: 300,
					width: 350,
					modal: true,
					buttons: {
						"Close": function() {
							$( this ).dialog( "close" );
						}
					}
				});
			});			
			
</script>
			
			
		</div> 
                
		<?php echo $pagination ?>  
		</div><!--/content-->
		<?php echo $footer ?>